// pages/myproorder/myproorder.js
const app = getApp(), token = wx.getStorageSync('token'), ent = app.globalData.ent;
import api from "../../../../utils/util";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    fullHeight: app.globalData.fullcontain,
    navmess: {
      navtitle: "我的项目订单",
      backhide: 0,
      topheight: 1,
    },
    currentTab: 0,
    height: 0,   //单个main高度
    widHeight: 0,  //swiper高度
    serachText: '', // 需搜索内容
    selectShow: false,
    selectData: ['全部'],//下拉列表的数据
    index: 0,//选择的下拉列表下标
    storeId: '',// 门店Id
    storeData: [''], // 城市下拉数据
    demolist:[],
    demolist2:[],
    demolist3:[],
    demolist4:[]
  },

  pageto: function(e){
    var url = e.currentTarget.dataset.url,
        data = e.currentTarget.dataset.datobj;
    app.goto(url,data);
  },
  // 动态获取赋值swiper-item高度
  savecurheight: function(count){
    this.setData({topNum: 0});
  },
  // 获取列表数据
  getDataList: function(status, orderNo, storeId){
    let obj;
    if(orderNo==undefined||orderNo==""){ //正常访问和左右切换=>搜索全部门店
      obj = {token: token, status: status};
    }else {// 搜索访问=>订单号
      if(storeId==undefined || storeId==""){
        obj = {token: token, status: status,orderNo: orderNo};
      }else{
        obj = {token: token, status: status,orderNo: orderNo,storeId: storeId};
      }
    }
    api.post('/mini/my/order/projectOrder',obj).then(res=>{
      let list = res.result.orderProjectViewList;
      if(status == 10){
        this.setData({demolist: list});
      }else if(status == 11){
        this.setData({demolist2: list});
      }else if(status == 12){
        this.setData({demolist3: list});
      }else{
        this.setData({demolist4: list});
      }
      console.log(list);
    })
  },
  // 获取状态判断
  getIsStatus: function(status, orderNo){
    let storeId = this.data.storeId;
    switch(status){
      case 0: // 待服务
        if(storeId == ""){
          this.getDataList(10,orderNo);
        }else{
          this.getDataList(10,orderNo,storeId);
        }
      break;
      case 1: // 服务中
        if(storeId == ""){
          this.getDataList(11,orderNo);
        }else{
          this.getDataList(11,orderNo,storeId);
        }
        break;
      case 2: // 门店留用
          if(storeId == ""){
            this.getDataList(12,orderNo);
          }else{
            this.getDataList(12,orderNo,storeId);
          }
        break;
      default: // 已服务
        if(storeId == ""){
          this.getDataList(13,orderNo);
        }else{
          this.getDataList(13,orderNo,storeId);
        }
      break;
    }
  },
  // 滑动切换tab
  bindChange: function (e) {
    var that = this;
    this.getIsStatus(e.detail.current);
    that.setData({currentTab: e.detail.current});
    this.savecurheight(e.detail.current);
  },
  // 点击tab切换
  swichNav: function (e) {
    var that = this;
    if (this.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  // 获取需要搜索的内容
  userNameInput: function(e){
    console.log(e.detail.value);
    this.setData({serachText: e.detail.value});
  },
  // 用户点击搜索(门店or全部)
  serachCommtiy: function(){
    this.getIsStatus(this.data.currentTab, this.data.serachText);
  },
  // 获取门店列表
  getToreSelectList: function(){
    api.post('/mini/store/storeSelectList',{ent: ent}).then(res=>{
      for(var key in res.result){
        this.data.selectData.push(res.result[key].name);
        this.data.storeData.push(res.result[key].id);
      }
      this.setData({selectData: this.data.selectData, storeData: this.data.storeData});
      console.log(this.data.storeData)
    })
  },
  bindPickerChange: function(e) {
    this.setData({index: e.detail.value});
    let list = this.data.storeData, index = parseInt(this.data.index);
    this.setData({storeId: list[index]})
    console.log("门店ID",list[index]);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    this.savecurheight(0);  //默认取索引为0swiper高度
    this.getDataList(10); // 10默认 待服务
    this.getToreSelectList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})